home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / DTS MPW Goodies / ChangeFileName < prev    next >
Encoding:
Text File  |  1990-09-14  |  5.1 KB  |  148 lines  |  [TEXT/MPS ]

  1.  
  2. #
  3. #    File:    ChangeFileName - Change the name of a file in a projector project.
  4. #    Date:    28 Mar 89
  5. #
  6. #    Copyright Apple Computer, Inc. 1989  All rights reserved.
  7. #
  8. #    DISCRIPTION:
  9. #        This is a script designed to make changing a file name under projector as painless
  10. #        as possible.  The script changes the name for every version in the projector
  11. #        project.  It also adds the following to the comment field:
  12. #            A note saying that the file name changed.
  13. #            The date of the original checkin.
  14. #            And the orginal comments.
  15. #        All the other information about the file is preserved also.  
  16. #        NOTE when the script is done, all the old revisions of the "old file" are removed,
  17. #        there is no trace or history of them left! (except in the new comment field that the
  18. #        name had been changed.
  19. #
  20. #        Status:    ChangeFileName may return the following status values:
  21. #                0        No Error.
  22. #                1        Error.
  23. #                2        Syntax Error.
  24. #                3        Old file is checked out for modification.
  25. #                4        Branch error, found that file had branches.
  26. #
  27. #
  28. #    CHANGE HISTORY:
  29. #
  30. #    28 Mar 89    EKH        New Today!
  31. #
  32.  
  33.  
  34. #
  35. # Set up some original variables used in this script
  36. #
  37.     Set Usage "Usage: ChangeFileName -project '<project>' <oldName> <newName>";
  38.  
  39. #
  40. # Now begin...
  41. #
  42.  
  43. Set Exit 0
  44. Begin
  45.     # Save the current directory...
  46.         Set currDir "`Directory`";
  47.     # Check the input parameters
  48.         IF ("{1}" !~ /-project/); 
  49.             Echo {Usage}; 
  50.             Exit 2;
  51.         ELSE
  52.             Set theProject "{2}";
  53.         END;
  54.     Set oldName "{3}"
  55.     Set newName "{4}"
  56.     # Check for safe usage....
  57.         IF ({oldName} == ""); Echo {Usage}; Exit 2; END;
  58.         IF ({newName} == ""); Echo {Usage}; Exit 2; END;
  59.     # If it's a fullpath name, get just the name, for error dialogs...
  60.         If "{oldName}" !~ /:*([¬:]+:*)*([¬:]+)®1/
  61.             Exit 2
  62.         End
  63.         Set shortOName "{®1}"                    # get short name for dialogs
  64.         If "{newName}" !~ /:*([¬:]+:*)*([¬:]+)®1/
  65.             Exit 2
  66.         End
  67.         Set shortNName "{®1}"                    # get short name for dialogs
  68.     # Check to make sure the project is mounted, and the current project...
  69.         Project "{theProject}" ∑ Dev:Null;
  70.         IF ({Status} != 0);
  71.             Alert "The project “{theProject}” is not currently mounted!";
  72.             Exit 1;
  73.         END;
  74.     # Check if the old file is checked out for Modification...
  75.         Set Info "`ProjectInfo -m "{oldName}"`"
  76.         If ("{Info}" != "")
  77.             Alert "{shortOName} is checked out for modification!  Please check it in and try again."
  78.             Exit 3
  79.         End
  80.     # Now get the complete project listing of that file along with comments.
  81.         Set longListing "`ProjectInfo -comments "{shortOName}"`"        
  82.     # Now make sure that there are't any branches, cause they are to complex to handle...
  83.         IF ( "{longListing}" =~ /(≈)({shortOName}[,]+[0-9]+[a-z]+[0-9]+)(≈)/);
  84.             Alert "The file {shortOName} has branches, this script can NOT handle files with braches, it is too complex!∂n∂nSorry!"
  85.             Exit 4;
  86.         END;
  87.     # Now change the name of all the specified revisions...
  88.         Set workingDir "{Boot}CFNtemp:";
  89.         NewFolder "{workingDir}";
  90.         Directory "{workingDir}";
  91.         Set currListing "{longListing}";
  92.  
  93.         Loop
  94.             (Evaluate "{currListing}" =~ /(≈)®1({shortOName}[,]+[0-9]+)®2([ ]«5»)([A]+≈)®3/) ∑ Dev:Null
  95.             Set currListing "{®1}";
  96.             Set currRev "{®2}"
  97.             Set currInfo "{®3}"
  98.             # Get the Version number
  99.                 (Evaluate "{currRev}" =~ /{shortOName},([0-9]+)®1/) ∑ Dev:Null
  100.                 Set versNum "{®1}";
  101.             # Seperate out the other parts of the file listing...
  102.                 (Evaluate "{currInfo}" =~ /≈'Author: '(≈)®1'Checked in: '(≈)®2'Task: '(≈)®3'Comment:'(≈)®4/) ∑ Dev:Null
  103.                 Set theAuthor "{®1}";
  104.                 Set orgDate "{®2}";
  105.                 Set theTask "{®3}";
  106.                 Set theComment "{®4}";
  107.                 (Evaluate "{theAuthor}" =~ /(≈)®1([ ]«5»)/) ∑ Dev:Null
  108.                 Set theAuthor "{®1}";
  109.                 (Evaluate "{orgDate}" =~ /(≈)®1([ ]«5»)/) ∑ Dev:Null
  110.                 Set orgDate "{®1}";
  111.                 (Evaluate "{theTask}" =~ /(≈)®1([ ]«5»)/) ∑ Dev:Null
  112.                 Set theTask "{®1}";
  113.             # Sometimes there are these BIG spaces in the comment, so this will remove them
  114.                 Loop
  115.                     IF ("{theComment}" !~ /(≈)®1('         ')(≈)®2/)
  116.                         Break;
  117.                     END;
  118.                     Set theComment "{®1} {®2}";
  119.                 END;
  120.             # Add some text to the comment...
  121.                 Set newComment "NAME CHANGED from {shortOName} to {shortNName}.∂nOrig. Checkin: {orgDate}.∂nOrig. Comments: {theComment}"
  122.             # Checkout the old version as read-only.
  123.                 Checkout -project "{theProject}" -noTouch -d "{workingDir}" "{shortOName},{versNum}";
  124.             # Orphan the old file
  125.                 OrphanFiles "{shortOName}";
  126.             # Now check in the new file with all the information we gathered.
  127.                 IF ({versNum} <= 1);
  128.                     Rename "{shortOName}" "{shortNName}";
  129.                     Checkin -new -delete -project "{theProject}" -u "{theAuthor}" -t "{theTask}" -cs "{newComment}" "{shortNName}";
  130.                 ELSE
  131.                     Checkout -noTouch -m -project "{theProject}" -d "{workingDir}" "{shortNName}";
  132.                     TransferCKID "{shortNName}" "{shortOName}";
  133.                     Delete "{shortNName}";
  134.                     Rename "{shortOName}" "{shortNName}";
  135.                     Checkin -y -delete -project "{theProject}" -u "{theAuthor}" -t "{theTask}" -cs "{newComment}" "{shortNName}";
  136.                 END;
  137.  
  138.             Break IF ("{currListing}" == "");
  139.         End;
  140.     # Restores the original directory.
  141.         Directory {currDir};
  142.     # Restores the original directory.
  143.         Delete -y "{WorkingDir}";
  144.     # Now that all the new files are checked in, we will delete all the old one out of the project.
  145.         DeleteRevisions -y -file -project "{theProject}" "{shortOName}";
  146. End
  147. Exit 0;
  148.